package values;

public class Array implements Value {
	
	private Value[] values;
	private int size;
	
	/**
	 * Creates a new Fanta array of Values with the java array a.
	 * @param a
	 */
	
	public Array (Value[] a) {
		this.values = a;
		this.size = a.length;
	}
	
	public int getSize() {
		return size;
	}

	public Array (Array a) {
		this.values = a.eval();
	}
	
	/**
	 * Returns the array of values
	 * @return
	 */
	
	public Value[] eval() {
		return this.values;
	}
	
	/**
	 * Returns the Value at index 'index' in the array
	 * @param index
	 * @return
	 */
	
	public Value eval(int index) {
		assert index >= 0;
		assert index < this.values.length;
		
		return this.values[index];
	}
	
	/**
	 * Updates the Value at index 'index' to 'a'
	 * @param index
	 * @param a
	 */
	
	public void update(int index, Value a) {
		assert index >= 0;
		assert index < this.values.length;
		
		this.values[index] = a;
	}
	
	public String toString() {
		String result = "";
		
		for (int i = 0; i < this.getSize(); i++) {
			result = result + this.values[i].toString();
			if (i < this.getSize()-1)
				result = result + " ";
		}
		
		return "array:[" + result + "]";
	}
}
